from langchain_text_splitters import RecursiveJsonSplitter
import requests

# 1.获取并加载json
url = "https://api.smith.langchain.com/openapi.json"
json_data = requests.get(url).json()

# 2. 递归json分割器
text_splitter = RecursiveJsonSplitter(max_chunk_size=300)

# 3. 分割json数据并创建文档
json_chunk = text_splitter.split_json(json_data)
chunks = text_splitter.create_documents(json_chunk)

# 4.输出内容
for chunk in chunks[:3]:
    print(chunk.page_content)

